package com.surfilter.phantomjs.util;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.Test;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class NumFormatUtils {

    private static Logger logger = LoggerFactory.getLogger(NumFormatUtils.class);

//	private static String regexfloat = "^[1-9]\\d*\\.\\d*[1-9]|0\\.\\d*[1-9]";

    private static String regexfloat = "[0-9]\\d*\\.\\d*|^0\\.\\d*[0-9]\\d*|[0-9]\\d*";

    private static String regexNum = "[0-9]+";

    private static String regexNumSplit = "[0-9]+(\\.)?";

    private static String regexChinese = "[\u4e00-\u9fa5]+";

    private static String regexSplit = "((,|\\s|，)*[0-9]+)+";

    private static String regexSpli1t = "[0-9]+";

    private static String regexSpli2t = "[0-9]+(,)?[0-9]+((,)?[0-9]+)*";

    private static String regexSpli3t = "([0-9]+(,)?)*(位|个|人|元)";

    private static String regexBiliW = ".*亿.*万.*";

    private static String regexB = ".*亿.*";

    private static String regexWY = ".*万.+";

    private static String regexW = ".*万";

    private static String regexBeforWY = ".*万元[^0-9]+([0-9]+(,|\\.|\\s|，)*)+";

    private static String regexSyl = "[0-9]{1,2}(\\.[0-9]{1,2})?";

    private static List<String> sjcList = new ArrayList<String>();

    private static List<String> dsjcList = new ArrayList<String>();


    static {
        sjcList.add("北京");
        sjcList.add("上海");
        sjcList.add("广东");
        sjcList.add("天津");
        sjcList.add("重庆");
        sjcList.add("辽宁");
        sjcList.add("河北");
        sjcList.add("河南");
        sjcList.add("四川");
        sjcList.add("江苏");
        sjcList.add("云南");
        sjcList.add("广西");
        sjcList.add("福建");
        sjcList.add("江西");
        sjcList.add("浙江");
        sjcList.add("吉林");
        sjcList.add("安徽");
        sjcList.add("山西");
        sjcList.add("内蒙古");
        sjcList.add("甘肃");
        sjcList.add("新疆");
        sjcList.add("海南");
        sjcList.add("贵州");
        sjcList.add("湖南");
        sjcList.add("湖北");
        sjcList.add("山东");
        sjcList.add("陕西");
        sjcList.add("宁夏");
        sjcList.add("青海");
        sjcList.add("西藏");
        sjcList.add("黑龙江");
        sjcList.add("香港");
        sjcList.add("澳门");
        sjcList.add("台湾");


        dsjcList.add("北京");
        dsjcList.add("天津");
        dsjcList.add("石家庄");
        dsjcList.add("唐山");
        dsjcList.add("秦皇岛");
        dsjcList.add("邯郸");
        dsjcList.add("邢台");
        dsjcList.add("保定");
        dsjcList.add("张家口");
        dsjcList.add("承德");
        dsjcList.add("沧州");
        dsjcList.add("廊坊");
        dsjcList.add("衡水");
        dsjcList.add("太原");
        dsjcList.add("大同");
        dsjcList.add("阳泉");
        dsjcList.add("长治");
        dsjcList.add("晋城");
        dsjcList.add("朔州");
        dsjcList.add("晋中");
        dsjcList.add("运城");
        dsjcList.add("忻州");
        dsjcList.add("临汾");
        dsjcList.add("吕梁");
        dsjcList.add("呼和浩特");
        dsjcList.add("包头");
        dsjcList.add("乌海");
        dsjcList.add("赤峰");
        dsjcList.add("通辽");
        dsjcList.add("鄂尔多斯");
        dsjcList.add("呼伦贝尔");
        dsjcList.add("巴彦淖尔");
        dsjcList.add("乌兰察布");
        dsjcList.add("兴安盟");
        dsjcList.add("锡林郭勒盟");
        dsjcList.add("阿拉善盟");
        dsjcList.add("沈阳");
        dsjcList.add("大连");
        dsjcList.add("鞍山");
        dsjcList.add("抚顺");
        dsjcList.add("本溪");
        dsjcList.add("丹东");
        dsjcList.add("锦州");
        dsjcList.add("营口");
        dsjcList.add("阜新");
        dsjcList.add("辽阳");
        dsjcList.add("盘锦");
        dsjcList.add("铁岭");
        dsjcList.add("朝阳");
        dsjcList.add("葫芦岛");
        dsjcList.add("金普新区");
        dsjcList.add("长春");
        dsjcList.add("吉林");
        dsjcList.add("四平");
        dsjcList.add("辽源");
        dsjcList.add("通化");
        dsjcList.add("白山");
        dsjcList.add("松原");
        dsjcList.add("白城");
        dsjcList.add("延边");
        dsjcList.add("哈尔滨");
        dsjcList.add("齐齐哈尔");
        dsjcList.add("鸡西");
        dsjcList.add("鹤岗");
        dsjcList.add("双鸭山");
        dsjcList.add("大庆");
        dsjcList.add("伊春");
        dsjcList.add("佳木斯");
        dsjcList.add("七台河");
        dsjcList.add("牡丹江");
        dsjcList.add("黑河");
        dsjcList.add("绥化");
        dsjcList.add("大兴安岭");
        dsjcList.add("上海");
        dsjcList.add("南京");
        dsjcList.add("无锡");
        dsjcList.add("徐州");
        dsjcList.add("常州");
        dsjcList.add("苏州");
        dsjcList.add("南通");
        dsjcList.add("连云港");
        dsjcList.add("淮安");
        dsjcList.add("盐城");
        dsjcList.add("扬州");
        dsjcList.add("镇江");
        dsjcList.add("泰州");
        dsjcList.add("宿迁");
        dsjcList.add("杭州");
        dsjcList.add("宁波");
        dsjcList.add("温州");
        dsjcList.add("嘉兴");
        dsjcList.add("湖州");
        dsjcList.add("绍兴");
        dsjcList.add("金华");
        dsjcList.add("衢州");
        dsjcList.add("舟山");
        dsjcList.add("台州");
        dsjcList.add("丽水");
        dsjcList.add("舟山新区");
        dsjcList.add("合肥");
        dsjcList.add("芜湖");
        dsjcList.add("蚌埠");
        dsjcList.add("淮南");
        dsjcList.add("马鞍山");
        dsjcList.add("淮北");
        dsjcList.add("铜陵");
        dsjcList.add("安庆");
        dsjcList.add("黄山");
        dsjcList.add("滁州");
        dsjcList.add("阜阳");
        dsjcList.add("宿州");
        dsjcList.add("六安");
        dsjcList.add("亳州");
        dsjcList.add("池州");
        dsjcList.add("宣城");
        dsjcList.add("福州");
        dsjcList.add("厦门");
        dsjcList.add("莆田");
        dsjcList.add("三明");
        dsjcList.add("泉州");
        dsjcList.add("漳州");
        dsjcList.add("南平");
        dsjcList.add("龙岩");
        dsjcList.add("宁德");
        dsjcList.add("南昌");
        dsjcList.add("景德镇");
        dsjcList.add("萍乡");
        dsjcList.add("九江");
        dsjcList.add("新余");
        dsjcList.add("鹰潭");
        dsjcList.add("赣州");
        dsjcList.add("吉安");
        dsjcList.add("宜春");
        dsjcList.add("抚州");
        dsjcList.add("上饶");
        dsjcList.add("济南");
        dsjcList.add("青岛");
        dsjcList.add("淄博");
        dsjcList.add("枣庄");
        dsjcList.add("东营");
        dsjcList.add("烟台");
        dsjcList.add("潍坊");
        dsjcList.add("济宁");
        dsjcList.add("泰安");
        dsjcList.add("威海");
        dsjcList.add("日照");
        dsjcList.add("莱芜");
        dsjcList.add("临沂");
        dsjcList.add("德州");
        dsjcList.add("聊城");
        dsjcList.add("滨州");
        dsjcList.add("菏泽");
        dsjcList.add("郑州");
        dsjcList.add("开封");
        dsjcList.add("洛阳");
        dsjcList.add("平顶山");
        dsjcList.add("安阳");
        dsjcList.add("鹤壁");
        dsjcList.add("新乡");
        dsjcList.add("焦作");
        dsjcList.add("濮阳");
        dsjcList.add("许昌");
        dsjcList.add("漯河");
        dsjcList.add("三门峡");
        dsjcList.add("南阳");
        dsjcList.add("商丘");
        dsjcList.add("信阳");
        dsjcList.add("周口");
        dsjcList.add("驻马店");
        dsjcList.add("武汉");
        dsjcList.add("黄石");
        dsjcList.add("十堰");
        dsjcList.add("宜昌");
        dsjcList.add("襄阳");
        dsjcList.add("鄂州");
        dsjcList.add("荆门");
        dsjcList.add("孝感");
        dsjcList.add("荆州");
        dsjcList.add("黄冈");
        dsjcList.add("咸宁");
        dsjcList.add("随州");
        dsjcList.add("恩施");
        dsjcList.add("长沙");
        dsjcList.add("株洲");
        dsjcList.add("湘潭");
        dsjcList.add("衡阳");
        dsjcList.add("邵阳");
        dsjcList.add("岳阳");
        dsjcList.add("常德");
        dsjcList.add("张家界");
        dsjcList.add("益阳");
        dsjcList.add("郴州");
        dsjcList.add("永州");
        dsjcList.add("怀化");
        dsjcList.add("娄底");
        dsjcList.add("湘西");
        dsjcList.add("广州");
        dsjcList.add("韶关");
        dsjcList.add("深圳");
        dsjcList.add("珠海");
        dsjcList.add("汕头");
        dsjcList.add("佛山");
        dsjcList.add("江门");
        dsjcList.add("湛江");
        dsjcList.add("茂名");
        dsjcList.add("肇庆");
        dsjcList.add("惠州");
        dsjcList.add("梅州");
        dsjcList.add("汕尾");
        dsjcList.add("河源");
        dsjcList.add("阳江");
        dsjcList.add("清远");
        dsjcList.add("东莞");
        dsjcList.add("中山");
        dsjcList.add("潮州");
        dsjcList.add("揭阳");
        dsjcList.add("云浮");
        dsjcList.add("南宁");
        dsjcList.add("柳州");
        dsjcList.add("桂林");
        dsjcList.add("梧州");
        dsjcList.add("北海");
        dsjcList.add("防城港");
        dsjcList.add("钦州");
        dsjcList.add("贵港");
        dsjcList.add("玉林");
        dsjcList.add("百色");
        dsjcList.add("贺州");
        dsjcList.add("河池");
        dsjcList.add("来宾");
        dsjcList.add("崇左");
        dsjcList.add("海口");
        dsjcList.add("三亚");
        dsjcList.add("三沙");
        dsjcList.add("重庆");
        dsjcList.add("两江新区");
        dsjcList.add("成都");
        dsjcList.add("自贡");
        dsjcList.add("攀枝花");
        dsjcList.add("泸州");
        dsjcList.add("德阳");
        dsjcList.add("绵阳");
        dsjcList.add("广元");
        dsjcList.add("遂宁");
        dsjcList.add("内江");
        dsjcList.add("乐山");
        dsjcList.add("南充");
        dsjcList.add("眉山");
        dsjcList.add("宜宾");
        dsjcList.add("广安");
        dsjcList.add("达州");
        dsjcList.add("雅安");
        dsjcList.add("巴中");
        dsjcList.add("资阳");
        dsjcList.add("阿坝");
        dsjcList.add("甘孜");
        dsjcList.add("凉山");
        dsjcList.add("贵阳");
        dsjcList.add("六盘水");
        dsjcList.add("遵义");
        dsjcList.add("安顺");
        dsjcList.add("毕节");
        dsjcList.add("铜仁");
        dsjcList.add("黔西南");
        dsjcList.add("黔东南");
        dsjcList.add("黔南");
        dsjcList.add("昆明");
        dsjcList.add("曲靖");
        dsjcList.add("玉溪");
        dsjcList.add("保山");
        dsjcList.add("昭通");
        dsjcList.add("丽江");
        dsjcList.add("普洱");
        dsjcList.add("临沧");
        dsjcList.add("楚雄");
        dsjcList.add("红河");
        dsjcList.add("文山");
        dsjcList.add("西双版纳");
        dsjcList.add("大理");
        dsjcList.add("德宏");
        dsjcList.add("怒江");
        dsjcList.add("迪庆");
        dsjcList.add("拉萨");
        dsjcList.add("日喀则");
        dsjcList.add("昌都");
        dsjcList.add("山南");
        dsjcList.add("那曲");
        dsjcList.add("阿里");
        dsjcList.add("林芝");
        dsjcList.add("西安");
        dsjcList.add("铜川");
        dsjcList.add("宝鸡");
        dsjcList.add("咸阳");
        dsjcList.add("渭南");
        dsjcList.add("延安");
        dsjcList.add("汉中");
        dsjcList.add("榆林");
        dsjcList.add("安康");
        dsjcList.add("商洛");
        dsjcList.add("西咸");
        dsjcList.add("兰州");
        dsjcList.add("嘉峪关");
        dsjcList.add("金昌");
        dsjcList.add("白银");
        dsjcList.add("天水");
        dsjcList.add("武威");
        dsjcList.add("张掖");
        dsjcList.add("平凉");
        dsjcList.add("酒泉");
        dsjcList.add("庆阳");
        dsjcList.add("定西");
        dsjcList.add("陇南");
        dsjcList.add("临夏");
        dsjcList.add("甘南");
        dsjcList.add("西宁");
        dsjcList.add("海东");
        dsjcList.add("海北");
        dsjcList.add("黄南");
        dsjcList.add("海南州");
        dsjcList.add("果洛");
        dsjcList.add("玉树");
        dsjcList.add("海西");
        dsjcList.add("银川");
        dsjcList.add("石嘴山");
        dsjcList.add("吴忠");
        dsjcList.add("固原");
        dsjcList.add("中卫");
        dsjcList.add("乌鲁木齐");
        dsjcList.add("克拉玛依");
        dsjcList.add("吐鲁番");
        dsjcList.add("哈密");
        dsjcList.add("昌吉");
        dsjcList.add("博尔塔拉");
        dsjcList.add("巴音郭楞");
        dsjcList.add("阿克苏");
        dsjcList.add("克孜勒苏");
        dsjcList.add("喀什");
        dsjcList.add("和田");
        dsjcList.add("伊犁");
        dsjcList.add("塔城");
        dsjcList.add("阿勒泰");
        dsjcList.add("台北");
        dsjcList.add("高雄");
        dsjcList.add("基隆");
        dsjcList.add("台中");
        dsjcList.add("台南");
        dsjcList.add("新竹");
        dsjcList.add("嘉义");
        dsjcList.add("新北");
        dsjcList.add("宜兰");
        dsjcList.add("桃园");
        dsjcList.add("新竹");
        dsjcList.add("苗栗");
        dsjcList.add("彰化");
        dsjcList.add("南投");
        dsjcList.add("云林");
        dsjcList.add("嘉义");
        dsjcList.add("屏东");
        dsjcList.add("台东");
        dsjcList.add("花莲");
        dsjcList.add("澎湖");
        dsjcList.add("金门");
        dsjcList.add("连江");
        dsjcList.add("香港岛");
        dsjcList.add("九龙");
        dsjcList.add("新界");
        dsjcList.add("澳门半岛");
        dsjcList.add("氹仔岛");
        dsjcList.add("路环岛");
    }

    public static long parseDay(String text) {
        long result = 0;
        String regexMD = "[0-9]\\d*\\.\\d*|^0\\.\\d*[0-9]\\d*|[0-9]\\d*\\s*个?\\s*月\\s*[0-9]\\d*\\.\\d*|^0\\.\\d*[0-9]\\d*|[0-9]\\d*\\s*天";
        String regexM = "[0-9]\\d*\\.\\d*|^0\\.\\d*[0-9]\\d*|[0-9]\\d*\\s*个?\\s*月";
        String regexD = "[0-9]\\d*\\.\\d*|^0\\.\\d*[0-9]\\d*|[0-9]\\d*\\s*天";
        if (existString(text, regexMD)) {
            result += parseStringNumToLongChen(text, regexM, 30);
            result += parseStringNumToLongChen(text, regexD, 1);
        } else if (existString(text, regexM)) {
            result += parseStringNumToLongChen(text, regexM, 30);
        } else if (existString(text, regexD)) {
            result += parseStringNumToLongChen(text, regexD, 1);
        }
        return result;
    }

    public static long parseNum(String text) {
        long result = 0;
        try {
            //判断是否含有中文
            String regB = "([0-9]+(,|\\.|\\s|，)*)*[^0-9]*亿";
            String regW = "([0-9]+(,|\\.|\\s|，)*)*[^0-9]*万";
            String regY = "万[^0-9]*([0-9]+(,|\\.|\\s|，)*)*";
            if (existString(text, regexChinese)) {
                if (existString(text, regexBiliW)) {
                    result += parseStringNumToLongChen(text, regB, 100000000);
                    result += parseStringNumToLongChen(text, regW, 10000);
                    result += parseStringNumToLongChen(text, regY, 1);
                } else if (existString(text, regexB)) {
                    result += parseStringNumToLongChen(text, regB, 100000000);
                } else if (existString(text, regexWY)) {
                    if (existString(text, regexBeforWY)) {
                        result += parseStringNumToLongChen(text, regexBeforWY, 10000);
                    } else {
                        result += parseStringNumToLongChen(text, regW, 10000);
                        result += parseStringNumToLongChen(text, regY, 1);
                    }
                } else if (existString(text, regexW)) {
                    result += parseStringNumToLongChen(text, regW, 10000);
                } else {
                    if (existString(text, regexSpli2t)) {
                        result += parseStringNumToLongChen(text, regexSpli2t, 1);
                    } else if (existString(text, regexSpli3t)) {
                        result += parseStringNumToLongChen(text, regexSpli3t, 1);
                    } else {
                        result = parseStringNumToLong(text);
                    }
                }
            } else {
                result = parseStringNumToLong(text);
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("数字格式转换异常：", e);
        }
        return result;
    }

    public static Double parseMaxSyl(String text) {
        Double result = null;
        try {
            if (!StringUtils.isEmpty(text)) {
                text = text.replace("\n", "");
            }
            List<String> resultS = parseString(text, regexSyl);
            if (resultS != null && !resultS.isEmpty()) {
                for (String str : resultS) {
                    Double res = Double.parseDouble(str);
                    if (result == null || res.doubleValue() > result.doubleValue()) {
                        result = res;
                    }
                }
            }
        } catch (Exception e) {
            logger.error("匹配综合收益率异常", e);
        }

        return result;
    }

    public static Double parseXmTzjd(String text) {
        if (StringUtils.isBlank(text)) return null;
        Double m = parseMaxSyl(text);
        if (text.contains("%")) m = m / 100;
        return m;
    }

    /**
     * 判断字符串中是否含有匹配项
     *
     * @param text
     * @return
     */
    public static boolean existString(String text, String regex) {
        if (text == null || text.trim().equalsIgnoreCase("")) return false;
        Pattern patt = Pattern.compile(regex);
        Matcher match = patt.matcher(text);
        return match.find();
    }

    private static long parseStringNumToLongChen(String text, String regex, long cheng) {

        long result = 0;
        text = parseString(text, regex, false);
        if (text == null || text.trim().equalsIgnoreCase("")) return 0;
        text = parseString(text, regexNumSplit, true);
        if (text == null || text.trim().equalsIgnoreCase("")) return 0;
        Double doub = Double.parseDouble(text) * cheng;
        if (doub > Long.MAX_VALUE) {
            result = 0;
        } else {
            result = doub.longValue();
        }
        return result;
    }

    /**
     * @param text     需要匹配的文本
     * @param regex    正则表达
     * @param regexAll 是否匹配所有
     * @return 返回匹配到的字符串
     */
    public static String parseString(String text, String regex, boolean regexAll) {
        StringBuffer strb = new StringBuffer();
        if (null == text) return strb.toString();
        Pattern patt = Pattern.compile(regex);
        Matcher match = patt.matcher(text);
        while (match.find()) {
            strb.append(match.group());
            if (!regexAll) break;
        }
        return strb.toString();
    }

    /**
     * @param text     需要匹配的文本
     * @param regex    正则表达
     * @return 返回匹配到的字符串
     */
    public static List<String> parseString(String text, String regex) {
        List<String> results = new ArrayList<String>();
        Pattern patt = Pattern.compile(regex);
        Matcher match = patt.matcher(text);
        while (match.find()) {
            results.add(match.group());
        }
        return results;
    }

    /**
     * 不含中文的数字解析
     *
     * @param text
     * @return
     */
    public static long parseStringNumToLong(String text) {
        long result = 0;
        try {
            text = parseString(text, regexSplit, false);
            if (text == null || text.trim().equalsIgnoreCase("")) return result;
            StringBuffer strb = new StringBuffer();
            Pattern patt = Pattern.compile(regexNum);
            Matcher match = patt.matcher(text);
            while (match.find()) {
                strb.append(match.group());
            }
            String str = strb.toString();
            if (StringUtils.isNumeric(str)) {
                result = Long.parseLong(str);
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("NUM格式转换异常", e);
        }
        return result;
    }

    /**
     * 不含中文的数字解析
     *
     * @param text
     * @return
     */
    public static String parseStringNumToString(String text) {
        String str = null;
        try {
            text = parseString(text, regexSplit, false);
            if (text == null || text.trim().equalsIgnoreCase("")) return str;
            StringBuffer strb = new StringBuffer();
            Pattern patt = Pattern.compile(regexNum);
            Matcher match = patt.matcher(text);
            while (match.find()) {
                strb.append(match.group());
            }
            str = strb.toString();
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("NUM格式转换异常", e);
        }
        return str;
    }

    public static long noParseStringNumToLong(String text) {
        long result = 0;
        try {
            text = parseString(text, regexSpli1t, true);
            if (text == null || text.trim().equalsIgnoreCase("")) return result;
            StringBuffer strb = new StringBuffer();
            Pattern patt = Pattern.compile(regexNum);
            Matcher match = patt.matcher(text);
            while (match.find()) {
                strb.append(match.group());
            }
            String str = strb.toString();
            if (StringUtils.isNumeric(str)) {
                result = Long.parseLong(str);
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("NUM格式转换异常", e);
        }
        return result;
    }

    /**
     * 科学计数转化为十进制字符串
     *
     * @param str
     * @return
     */
    public static String getVatas(String str) {
        String target = null;
        if (str != null && !str.trim().equalsIgnoreCase("")) {
            try {
                BigDecimal bd = new BigDecimal(str.trim());
                target = bd.toPlainString();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return target;
    }

    public static String getNumbersNotZeroEnd(String str) {
        if (StringUtils.isEmpty(str)) return null;
        return parseString(str, regexfloat, false);
    }

    public static String subZeroAndDot(String str) {
        String s = parseString(str, regexfloat, true);
        if (StringUtils.isEmpty(s)) return null;
        if (s.indexOf(".") > 0) {
            s = s.replaceAll("0+?$", "");//去掉多余的0
            s = s.replaceAll("[.]$", "");//如最后一位是.则去掉
        }
        return s;
    }

    public static Integer getZjLevel(String str) {
        if (StringUtils.isEmpty(str)) return null;
        String money = parseString(str, regexNum, false);
        if (StringUtils.isEmpty(money)) return null;
        return money.length() - 1;

    }

    public static void main(String[] args) throws IOException {
//		List<String> results = FileUtils.readLines(new File("C:\\Users\\xubin\\workspace\\funds_taskt\\appxzl"), "utf-8");
//		for(String result : results){
//			System.out.println(parseNum(result) + "---" + result);
//		}
//		String mats = "预期收益率\n13 % +0.8%";
//		System.out.println(parseMaxSyl(mats) + "---" + mats);

        String str = ""
                + "												6.15%									"
                + "										";

//		String parseString = parseString(str,regexfloat,false);
//		System.out.println(parseString);
        System.out.println(parseMaxSyl(str));
//		System.out.println(parseStringNumToString(str));
//		System.out.println(getZjLevel(subZeroAndDot(str)));
//		System.out.println("------"+parseString+"-----");
//		System.out.println(parseStringNumToString(str));
//		System.out.println(Long.parseLong(mats));
//		System.out.println(StringUtils.isNumeric("123.09"));
//		System.out.println(getExSubString("市东城县", "县"));

        System.out.println(parseDay("5天"));
    }

    //获取省匹配信息
    public static String getProvinceShortname(String address) {
        if (!StringUtils.isEmpty(address)) {
            List<String> list = new ArrayList<String>();
            for (String sjc : sjcList) {
                if (address.contains(sjc)) {
                    list.add(sjc);
                }
            }
            if (list.size() > 0)
                return list.get(0);

        }
        return null;
    }

    //获取市匹配信息
    public static String getCityShortname(String address) {
        if (!StringUtils.isEmpty(address)) {
            Map<Integer, String> map = new HashMap<Integer, String>();
            for (String dsjc : dsjcList) {
                if (address.contains(dsjc)) {
                    int index = address.indexOf(dsjc);

                    map.put(index, dsjc);
                }
            }
            Object minKey = getMinKey(map);
            String value = map.get(minKey);

            return value;

        }

        return null;
    }

    /* 求Map<K,V>中Key(键)的最小值
    * @param map
    * @return
    */
    public static Object getMinKey(Map<Integer, String> map) {
        if (map == null || map.size() == 0) return null;
        Set<Integer> set = map.keySet();
        Object[] obj = set.toArray();
        Arrays.sort(obj);
        return obj[0];
    }

    //获取省市区信息
    public static String getExSubString(String str, String ssq) {
        if (!StringUtils.isEmpty(str)) {
            //获取省
            if ("省".equals(ssq)) {
                if (str.contains("北京") && "省".equals(ssq)) return "北京市";
                if (str.contains("天津") && "省".equals(ssq)) return "天津市";
                if (str.contains("上海") && "省".equals(ssq)) return "上海市";
                if (str.contains("重庆") && "省".equals(ssq)) return "重庆市";
                if (str.contains("省")) {
                    int indexPro = str.indexOf("省");
                    String pro = str.substring(0, indexPro + 1);
                    return pro;
                }

            }


            //获取市
            if ("市".equals(ssq)) {
                if (str.contains("北京") && "市".equals(ssq)) return "北京市";
                if (str.contains("天津") && "市".equals(ssq)) return "天津市";
                if (str.contains("上海") && "市".equals(ssq)) return "上海市";
                if (str.contains("重庆") && "市".equals(ssq)) return "重庆市";
                if (str.contains("市")) {
                    if (str.contains("市")) {
                        int indexCityEnd = str.indexOf("市");
                        int indexCityStart = str.indexOf("省");
                        if (indexCityStart >= 0 && indexCityStart < indexCityEnd) {
                            return str.substring(indexCityStart + 1, indexCityEnd + 1);

                        } else {
                            //int indexCityEnd = str.indexOf("市");
                            return str.substring(0, indexCityEnd + 1);
                        }
                    }
                }
            }


            //获取区
            if ("区".equals(ssq)) {
                if (str.contains("区")) {
                    //int indexOfRegEnd = str.indexOf("县");
                    int indexOfRegEnd1 = str.indexOf("区");
                    int indexOfRegStart = str.indexOf("市");
                    if (indexOfRegStart < 0) indexOfRegStart = str.indexOf("省");
                    if (indexOfRegStart >= 0 && indexOfRegStart < indexOfRegEnd1) {
                        return str.substring(indexOfRegStart + 1, indexOfRegEnd1 + 1);
                    } else {
                        return str.substring(0, indexOfRegEnd1 + 1);
                    }
//						if(indexOfRegEnd > 0){  //含有县
//							if(indexOfRegStart > 0 && indexOfRegStart < indexOfRegEnd ){
//								return str.substring(indexOfRegStart+1, indexOfRegEnd+1);
//							}else{
//								return str.substring(0, indexOfRegEnd+1);
//							}
//
//						}else{ //含区
//							if(indexOfRegStart > 0 && indexOfRegStart < indexOfRegEnd ){
//								return str.substring(indexOfRegStart+1, indexOfRegEnd+1);
//							}else{
//								return str.substring(0, indexOfRegEnd+1);
//							}
//						}
                }
            }
            //获取县
            if ("县".equals(ssq)) {
                if (str.contains("县")) {
                    int indexOfRegEnd = str.indexOf("县");
                    //int indexOfRegEnd1 = str.indexOf("区");
                    int indexOfRegStart = str.indexOf("市");
                    if (indexOfRegStart < 0) indexOfRegStart = str.indexOf("省");
                    if (indexOfRegStart >= 0 && indexOfRegStart < indexOfRegEnd) {
                        return str.substring(indexOfRegStart + 1, indexOfRegEnd + 1);
                    } else {
                        return str.substring(0, indexOfRegEnd + 1);
                    }
                }
            }

        }
        return null;
    }

    @Test
    public void testOne() {
        String dateStr = "0.7个月";
        System.out.println(parseDay(dateStr));
    }

//	@Test
//	public void testFile() throws IOException{
//		List<String> list = FileUtils.readLines(new File("E:/workspace/funds_task/file/2016-11-08"), "utf-8");
//		list.forEach((str) -> {
//			long day = parseDay(str);
//			System.out.println(str + "," + day);
//		});
//	}


}
